#ifndef _P2P_PEER_H_
#define _P2P_PEER_H_

#include "p2p-piece.h"

#define INIT 0
#define HS_SENT 1
#define CONNECTED 2
#define DATA_EXCHANGE 3

typedef struct peer_t {
    int psfd;
    uint8_t state;
    uint8_t data_exchange;
    char *data_recvd;
    uint32_t bytes_recvd;
    uint8_t data_pending;
    struct piece_t *piece_head;
    struct piece_t *piece;
    struct piece_t *piece_tail;
    uint32_t piece_count;
    uint8_t *piece_map;
    struct peer_t *prev;
    struct peer_t *next;
} peer_t;

typedef struct {
    peer_t *head;
    peer_t *tail;
    uint32_t count;
} peer_list_t;

peer_t *init_peer(int psfd);
peer_t *add_peer(peer_t *peer_tail, int psfd);
int del_peer(peer_t **peer_head, peer_t **peer_tail, peer_t *peer);
peer_t *search_peer(peer_t *head, int psfd);

#endif // ifndef _P2P_PEER_H_ 

